package interview.swap;

public class Swap {
	public int[] bitwise(int[] array) {
		/**
		 * Swap without additional variable
		 * For example:
		 * a=100=01100100 
		 * b=112=01110000
		 * c=a^b=00010100
		 * Now we know
		 * a=b^c、b=a^c、c=a^b
		 */
		array[0] ^= array[1];
		array[1] ^= array[0];
		array[0] ^= array[1];
		
		return array;
	}
	
	public int[] conditionalOperator(int[] array) {
		array[1] = array[0] + 0 * (array[0]=array[1]);
		return array;
	}
	
	public int[] mathimatic(int[] array) {
		array[0] = array[0] + array[1];
		array[1] = array[0] - array[1];
		array[0] = array[0] - array[1];
		
		return array;
	}
}
